using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using HengTong.Model.Db.SupplyChain.Material;
using TiaoTaoHelper.Wtm.Models;
using WalkingTec.Mvvm.Core;

namespace HengTong.Model.Db.SupplyChain.Purchase;

/// <summary>
/// 采购立项明细表
/// </summary>
/// <remarks>
/// 记录采购立项的具体物料明细信息，从采购需求池中选择需求明细进行立项，
/// 支持多申请单、多物料组合立项
/// </remarks>
[Display(Name = "采购立项明细", Description = "记录采购立项的具体物料明细信息", GroupName = "供应链")]
public class SysPurchaseProjectEntry : BasePoco
{
    #region 关联信息

    /// <summary>
    /// 获取或设置立项主表
    /// </summary>
    /// <value>关联的采购立项主表实体</value>
    [Display(Name = "采购立项", Description = "关联的采购立项主表", GroupName = "关联信息")]
    public SysPurchaseProject Project { get; set; }

    /// <summary>
    /// 获取或设置立项ID
    /// </summary>
    /// <value>关联的采购立项主表ID</value>
    [Required(ErrorMessage = "立项ID不能为空")]
    [Display(Name = "立项ID", Description = "关联的采购立项主表ID", GroupName = "关联信息")]
    public Guid? ProjectId { get; set; }

    /// <summary>
    /// 获取或设置需求池主表
    /// </summary>
    /// <value>关联的需求池主表实体</value>
    [Display(Name = "需求池", Description = "关联的需求池主表", GroupName = "关联信息")]
    public SysPurchaseRequirementPool Pool { get; set; }

    /// <summary>
    /// 获取或设置需求池ID
    /// </summary>
    /// <value>关联的需求池主表ID</value>
    [Required(ErrorMessage = "需求池ID不能为空")]
    [Display(Name = "需求池ID", Description = "关联的需求池主表ID", GroupName = "关联信息")]
    public Guid? PoolId { get; set; }
    
    /// <summary>
    /// 获取或设置需求明细
    /// </summary>
    /// <value>关联的需求池明细表实体</value>
    [Display(Name = "需求明细", Description = "关联的需求池明细表", GroupName = "关联信息")]
    public SysPurchaseRequirementPoolEntry PoolEntry { get; set; }

    /// <summary>
    /// 获取或设置需求明细ID
    /// </summary>
    /// <value>关联的需求池明细表ID，唯一索引：同一需求明细不能重复立项</value>
    [Required(ErrorMessage = "需求明细ID不能为空")]
    [Display(Name = "需求明细ID", Description = "关联的需求池明细表ID", GroupName = "关联信息")]
    public Guid? PoolEntryId { get; set; }

    /// <summary>
    /// 获取或设置采购申请单
    /// </summary>
    /// <value>关联的采购申请单主表实体</value>
    [Display(Name = "采购申请单", Description = "关联的采购申请单主表", GroupName = "关联信息")]
    public SysPurchaseRequestBill RequestBill { get; set; }

    /// <summary>
    /// 获取或设置采购申请单ID
    /// </summary>
    /// <value>关联的采购申请单主表ID</value>
    [Required(ErrorMessage = "申请单ID不能为空")]
    [Display(Name = "申请单ID", Description = "关联的采购申请单主表ID", GroupName = "关联信息")]
    public Guid? RequestBillId { get; set; }
    
    /// <summary>
    /// 获取或设置申请单明细
    /// </summary>
    /// <value>关联的采购申请单明细表实体</value>
    [Display(Name = "申请单明细", Description = "关联的采购申请单明细表", GroupName = "关联信息")]
    public SysPurchaseRequestBillEntry RequestBillEntry { get; set; }

    /// <summary>
    /// 获取或设置申请单明细ID
    /// </summary>
    /// <value>关联的采购申请单明细表ID</value>
    [Required(ErrorMessage = "申请单明细ID不能为空")]
    [Display(Name = "申请单明细ID", Description = "关联的采购申请单明细表ID", GroupName = "关联信息")]
    public Guid? RequestBillEntryId { get; set; }

    #endregion

    #region 申请信息

    /// <summary>
    /// 获取或设置申请部门
    /// </summary>
    /// <value>申请采购的部门实体</value>
    [Display(Name = "申请部门", Description = "申请采购的部门", GroupName = "申请信息")]
    public SysGroup RequestGroup { get; set; }

    /// <summary>
    /// 获取或设置申请部门ID
    /// </summary>
    /// <value>申请采购的部门ID</value>
    [Required(ErrorMessage = "申请部门ID不能为空")]
    [Display(Name = "申请部门ID", Description = "申请采购的部门ID", GroupName = "申请信息")]
    public Guid? RequestGroupId { get; set; }
    
    /// <summary>
    /// 获取或设置申请人
    /// </summary>
    /// <value>申请人姓名</value>
    [Required(ErrorMessage = "申请人不能为空")]
    [Display(Name = "申请人", Description = "申请人姓名", GroupName = "申请信息")]
    [StringLength(64)]
    public string RequestBy { get; set; }

    #endregion

    #region 物料信息

    /// <summary>
    /// 获取或设置物料
    /// </summary>
    /// <value>采购的物料实体信息</value>
    [Display(Name = "物料", Description = "采购的物料", GroupName = "物料信息")]
    public SysMaterial Material { get; set; }

    /// <summary>
    /// 获取或设置物料ID
    /// </summary>
    /// <value>采购的物料ID</value>
    [Required(ErrorMessage = "物料ID不能为空")]
    [Display(Name = "物料ID", Description = "采购的物料ID", GroupName = "物料信息")]
    public Guid? MaterialId { get; set; }

    /// <summary>
    /// 获取或设置物料SKU
    /// </summary>
    /// <value>采购的物料规格实体信息</value>
    [Display(Name = "物料规格", Description = "采购的物料规格", GroupName = "物料信息")]
    public SysMaterialSku MaterialSku { get; set; }

    /// <summary>
    /// 获取或设置物料SKU ID
    /// </summary>
    /// <value>采购的物料规格ID</value>
    [Display(Name = "物料规格ID", Description = "采购的物料规格ID", GroupName = "物料信息")]
    public Guid? MaterialSkuId { get; set; }
    
    #endregion

    #region 数量和金额

    /// <summary>
    /// 获取或设置需求数量
    /// </summary>
    /// <value>需求池中的申请数量，精度6位小数</value>
    [Required(ErrorMessage = "需求数量不能为空")]
    [Display(Name = "需求数量", Description = "需求池中的申请数量", GroupName = "数量和金额")]
    [Column(TypeName = "decimal(18,6)")]
    public decimal? RequestQuantity { get; set; }

    /// <summary>
    /// 获取或设置立项数量
    /// </summary>
    /// <value>本次立项采购数量，可小于等于需求数量，精度6位小数</value>
    [Required(ErrorMessage = "立项数量不能为空")]
    [Display(Name = "立项数量", Description = "本次立项采购数量", GroupName = "数量和金额")]
    [Column(TypeName = "decimal(18,6)")]
    public decimal? ProjectQuantity { get; set; }

    /// <summary>
    /// 获取或设置预计单价
    /// </summary>
    /// <value>预估采购单价，精度6位小数，可修改</value>
    [Required(ErrorMessage = "预计单价不能为空")]
    [Display(Name = "预计单价", Description = "预估采购单价", GroupName = "数量和金额")]
    [Column(TypeName = "decimal(18,6)")]
    public decimal? EstimatedPrice { get; set; }

    /// <summary>
    /// 获取或设置预算金额
    /// </summary>
    /// <value>立项数量 × 预计单价，精度2位小数</value>
    [Required(ErrorMessage = "预算金额不能为空")]
    [Display(Name = "预算金额", Description = "立项数量 × 预计单价", GroupName = "数量和金额")]
    [Column(TypeName = "decimal(18,2)")]
    public decimal? BudgetAmount { get; set; }

    #endregion

    #region 采购类型

    /// <summary>
    /// 获取或设置采购类型
    /// </summary>
    /// <value>采购类型：常规、设备新增、安全新增、其他</value>
    [Required(ErrorMessage = "采购类型不能为空")]
    [Display(Name = "采购类型", Description = "采购类型：常规、设备新增、安全新增、其他", GroupName = "采购类型")]
    public PurchaseType? PurchaseType { get; set; }

    /// <summary>
    /// 获取或设置物料类型
    /// </summary>
    /// <value>物料类型：备品备件、化工小料、大宗原材料</value>
    [Required(ErrorMessage = "物料类型不能为空")]
    [Display(Name = "物料类型", Description = "物料类型：备品备件、化工小料、大宗原材料", GroupName = "采购类型")]
    public MaterialType? MaterialType { get; set; }

    /// <summary>
    /// 获取或设置紧急程度
    /// </summary>
    /// <value>紧急程度：一般、紧急</value>
    [Required(ErrorMessage = "紧急程度不能为空")]
    [Display(Name = "紧急程度", Description = "紧急程度：一般、紧急", GroupName = "采购类型")]
    public UrgencyLevel? UrgencyLevel { get; set; }

    #endregion

    #region 时间和策略

    /// <summary>
    /// 获取或设置要求到货日期
    /// </summary>
    /// <value>原需求的要求到货日期</value>
    [Required(ErrorMessage = "要求到货日期不能为空")]
    [Display(Name = "要求到货日期", Description = "原需求的要求到货日期", GroupName = "时间和策略")]
    public DateTime? RequiredDeliveryDate { get; set; }

    /// <summary>
    /// 获取或设置采购策略
    /// </summary>
    /// <value>采购策略：询比价、招投标、协议采购，可调整</value>
    [Required(ErrorMessage = "采购策略不能为空")]
    [Display(Name = "采购策略", Description = "采购策略：询比价、招投标、协议采购", GroupName = "时间和策略")]
    public PurchaseStrategy? PurchaseStrategy { get; set; }

    #endregion

    #region 技术要求和备注

    /// <summary>
    /// 获取或设置技术要求
    /// </summary>
    /// <value>从申请单明细带出，可补充</value>
    [Display(Name = "技术要求", Description = "技术规格要求", GroupName = "技术要求和备注")]
    [StringLength(1024)]
    public string TechnicalRequirement { get; set; }

    /// <summary>
    /// 获取或设置备注
    /// </summary>
    /// <value>本明细行的补充说明</value>
    [Display(Name = "备注", Description = "本明细行的补充说明", GroupName = "技术要求和备注")]
    [StringLength(512)]
    public string Remark { get; set; }

    #endregion

    #region 排序

    /// <summary>
    /// 获取或设置行序号
    /// </summary>
    /// <value>明细行显示顺序</value>
    [Display(Name = "行序号", Description = "明细行显示顺序", GroupName = "排序")]
    public int RowIndex { get; set; }

    #endregion
}

